package com.gym.Thread;
/**
 * 单列模式懒汉模式，在多线程保证获得的实列对象是一个
 * @author Administrator
 *
 */
public class TestSingleton {
	public static void main(String[] args) {
		Singleton singleton= Singleton.getInstance();
		Singleton singleton1= Singleton.getInstance();
		System.err.println(singleton == singleton1);
	}
}
class Singleton{
	private static Singleton  singleton= null;
	public Singleton() {}
	public static Singleton getInstance(){
		synchronized(Singleton.class){
			if(singleton==null){
				singleton = new Singleton();
			}
		}
		return singleton;
	}
}
